package android.slc.appbase.utils;

import com.blankj.utilcode.util.CollectionUtils;
import com.blankj.utilcode.util.ServiceUtils;

/**
 * @author slc
 * @date 2021/4/26 13:39
 */
public class AppServiceUtils {
    public static void stopAllService() {
        stopAllService(null);
    }

    public static void stopAllService(OnStopAllFilter onStopAllFilter) {
        CollectionUtils.forAllDo(ServiceUtils.getAllRunningServices(), (index, item) -> {
            if (onStopAllFilter == null || !onStopAllFilter.isStop(item)) {
                try {
                    ServiceUtils.stopService(item);
                } catch (Exception e) {
                }
            }
        });
    }

    public interface OnStopAllFilter {
        boolean isStop(String serviceName);
    }
}
